//Main Funktion aufrufen
KwickPlus_Main();

function KwickPlus_Main()
{
  //Lade Optionen (von localStorage aus background.html) und rufe KwickPlus_Init auf
  KwickPlus_loadOptions();
}

function KwickPlus_Init()
{
  KwickPlus_AddCssStyle();
  KwickPlus_AddHtml();
  KwickPlus_AddJavaScript();

  //Photo Zoom
  PhotoZoom_Init();
}

function KwickPlus_loadOptions()
{
  chrome.extension.sendRequest
  (
  {"method": "getOptions"}, function(response)
  {
    options = response.value;
    KwickPlus_Init();
  }
  );
}

function KwickPlus_AddCssStyle()
{
  $("head").append('<link type="text/css" href="' + chrome.extension.getURL("css/custom-theme/jquery-ui-1.8.8.custom.css") + '" rel="stylesheet">');
  $("head").append('<link type="text/css" href="' + chrome.extension.getURL("css/options.css") + '" rel="stylesheet">');
}
function KwickPlus_AddHtml()
{
  function addFile(file)
  {    
    chrome.extension.sendRequest({"method": "readFile", "url": chrome.extension.getURL(file)}, onResponse);
  }
  function onResponse (response)
  {    
    $("body").append(response.value);
  }
  
  addFile("html/options.html");
}
function KwickPlus_AddJavaScript()
{
  var JavaScriptFileCount = 1;
  
  function addFile(file)
  {    
    chrome.extension.sendRequest({"method": "readFile", "url": chrome.extension.getURL(file)}, onResponse);
  }
  function onResponse (response)
  {    
    injectScript(response.value);
    JavaScriptFileCount++;
    
    switch(JavaScriptFileCount)
    {
      //2.
      case 2:
        addFile("js/jquery-ui-1.8.8.custom.min.js");
        break;
      
      //3.
      case 3:
        addFile("js/options.js");
        break;
        
      //4.
      case 4:
        injectScript("options_init();");
        break;
    }
    
  }
  
  //1.
  addFile("js/jquery-1.4.4.min.js");
}